package com.yjj.im.Utils;

import com.google.gson.Gson;

import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by Administrator on 2018/6/25.
 */

public class GsonUtil {

    private Gson gson;

    private GsonUtil(){
        gson = new Gson();
    }

    private static Gson create(){
        return Holder.instance.gson;
    }

    private static class Holder{
        private static final GsonUtil instance = new GsonUtil();
    }

    public static String toJson(Object object){
        return create().toJson(object);
    }

    public static List<?> fromJson(String json, Type type) {
        return create().fromJson(json, type);
    }

    public static <T> T fromJson(String json, Class<T> clazz) {
        return create().fromJson(json, clazz);
    }
}
